<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        #myBtn {
            display: none;
            position: fixed;
            bottom: 20px;
            right: 45px;
            font-size: 13px;
            line-height: 14px;
            z-index: 99;
            border: none;
            outline: none;
            background-color: rgba(125, 0, 0, 0.35);
            color: white;
            cursor: pointer;
            padding: 11px;
            border-radius: 50px;
        }

        #myBtn:hover {
            background-color: #DC1414;
        }

    </style>
</head>
<body>
<!--返回顶部特效-->
<div style="background-color: #2cc9ff;height: 2000px"></div>
<button onclick="topFunction()" id="myBtn" title="回顶部">返回 <br>顶部</button>
</body>
</html>
<script type="text/javascript">
    window.onload = function () {
// 当网页向下滑 "返回顶部"
        var mybtn = document.getElementById("myBtn");
        var timer = null;

        window.onscroll = function () {
            var sT = document.documentElement.scrollTop || document.body.scrollTop;
            if (sT >= 800) {
                mybtn.style.display = 'block';
            } else {
                mybtn.style.display = 'none';
            }

        };
        mybtn.onclick = function () {
            clearInterval(timer);
            timer = setInterval(function () {

                document.documentElement.scrollTop -= 100;
                document.body.scrollTop -= 100;
                var sT = document.documentElement.scrollTop || document.body.scrollTop;
                if (sT <= 0) {
                    clearInterval(timer);
                }

            }, 30)
        };


    };


</script>